/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    sha256.h
 *  @brief   Secure hash algorithm 256 header file.
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#ifndef __SHA256_H__
#define __SHA256_H__

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/* SHA-256 block size */
#define SHA256_BLOCK_SIZE      64
/* SHA-256 digest size */
#define SHA256_DIGEST_SIZE     32
/* Minimum length of the padding string */
#define SHA256_MIN_PAD_SIZE    9

extern const uint8_t sha256oid[9];

/**
 * SHA-256 algorithm context
 **/
struct sha256_context {
	union {
		uint32_t h[8];
		uint8_t  digest[32];
	};
	union {
		uint32_t w[16];
		uint8_t  buffer[64];
	};
	size_t   size;
	uint64_t total_size;
};

void sha256_compute(const void *data, size_t length, uint8_t *digest);
void sha256_init(struct sha256_context *context);
void sha256_update(struct sha256_context *context, const void *data, size_t length);
void sha256_final(struct sha256_context *context, uint8_t *digest);
void sha256_final_raw(struct sha256_context *context, uint8_t *digest);
void sha256_process_block(struct sha256_context *context);

#ifdef __cplusplus
}
#endif

#endif /* __SHA265_H__ */

